/*   1:    */ package gov.sat.tax.fwsk.wlrz;
/*   2:    */ 
/*   3:    */ import java.io.PrintStream;
/*   4:    */ import java.sql.Date;
/*   5:    */ import java.text.DecimalFormat;
/*   6:    */ import java.util.HashMap;
/*   7:    */ import java.util.List;
/*   8:    */ import java.util.Map;
/*   9:    */ 
/*  10:    */ public class CmpHandler
/*  11:    */ {
/*  12:    */   private InFpDataBean inData;
/*  13:    */   private JmFpDataBean jmData;
/*  14: 16 */   private int wxyy = 0;
/*  15: 17 */   private int rzjg = 0;
/*  16: 18 */   private int fp_status = 0;
/*  17:    */   private Date rdDate;
/*  18: 20 */   private boolean isNewClient = false;
/*  19:    */   
/*  20:    */   public CmpHandler()
/*  21:    */   {
/*  22: 24 */     this.inData = new InFpDataBean();
/*  23: 25 */     this.jmData = new JmFpDataBean();
/*  24:    */   }
/*  25:    */   
/*  26:    */   public boolean cmpRdDate(Date rdDate, String kprq)
/*  27:    */   {
/*  28: 38 */     boolean tmpBz = false;
/*  29: 39 */     if (rdDate == null) {
/*  30: 40 */       rdDate = new Date(System.currentTimeMillis());
/*  31:    */     }
/*  32: 41 */     if (kprq == null) {
/*  33: 42 */       kprq = "19000101";
/*  34:    */     }
/*  35: 44 */     if (kprq.length() == 8) {
/*  36: 45 */       kprq = kprq.substring(2);
/*  37:    */     }
/*  38: 46 */     String mYear = kprq.substring(0, 2);
/*  39: 47 */     String mMonth = kprq.substring(2, 4);
/*  40: 48 */     String mDay = kprq.substring(4, 6);
/*  41: 49 */     String curSKpRq = "20" + mYear + "-" + mMonth + "-" + mDay;
/*  42:    */     
/*  43: 51 */     Date curKpRq = new Date(System.currentTimeMillis());
/*  44: 52 */     curKpRq = Date.valueOf(curSKpRq);
/*  45: 53 */     if (curKpRq.before(rdDate)) {
/*  46: 54 */       tmpBz = true;
/*  47:    */     }
/*  48: 56 */     if (curKpRq.equals(rdDate)) {
/*  49: 57 */       tmpBz = false;
/*  50:    */     }
/*  51: 59 */     if (curKpRq.after(rdDate)) {
/*  52: 60 */       tmpBz = false;
/*  53:    */     }
/*  54: 62 */     return tmpBz;
/*  55:    */   }
/*  56:    */   
/*  57:    */   public Map doCmpProc()
/*  58:    */   {
/*  59: 66 */     Map map = new HashMap();
/*  60: 67 */     System.out.println("数据比对开始" + this.jmData.getErrNo());
/*  61: 68 */     if ((this.jmData.getErrNo() == 0) || (this.jmData.getErrNo() == 1001) || 
/*  62: 69 */       (this.jmData.getErrNo() == 1002))
/*  63:    */     {
/*  64: 71 */       this.fp_status = 0;
/*  65: 72 */       this.wxyy = 0;
/*  66: 73 */       this.rzjg = 0;
/*  67: 74 */       String fp_kprq = this.inData.getKprq();
/*  68: 75 */       if (fp_kprq.length() == 8) {
/*  69: 76 */         fp_kprq = this.inData.getKprq().substring(2);
/*  70:    */       }
/*  71: 79 */       if (WlrzConst.isDebug()) {
/*  72: 80 */         System.out.println("比较发票代码" + this.inData.getFp_dm() + "  " + 
/*  73: 81 */           this.jmData.getFp_dm());
/*  74:    */       }
/*  75: 82 */       if (!this.inData.getFp_dm().equals(this.jmData.getFp_dm()))
/*  76:    */       {
/*  77: 83 */         this.wxyy |= 0x40;
/*  78: 84 */         map.put("fpdm", this.jmData.getFp_dm());
/*  79:    */       }
/*  80: 88 */       if (WlrzConst.isDebug()) {
/*  81: 89 */         System.out.println("比较开票时间" + this.inData.getKprq() + "  " + 
/*  82: 90 */           this.jmData.getKprq());
/*  83:    */       }
/*  84: 91 */       if (!fp_kprq.equals(this.jmData.getKprq()))
/*  85:    */       {
/*  86: 92 */         this.wxyy |= 0x20;
/*  87: 93 */         map.put("kprq", this.jmData.getKprq());
/*  88:    */       }
/*  89: 97 */       if (WlrzConst.isDebug()) {
/*  90: 98 */         System.out.println("比较发票号码" + this.inData.getFp_hm() + "  " + 
/*  91: 99 */           this.jmData.getFp_hm());
/*  92:    */       }
/*  93:100 */       if (!this.inData.getFp_hm().equals(this.jmData.getFp_hm()))
/*  94:    */       {
/*  95:101 */         this.wxyy |= 0x10;
/*  96:102 */         map.put("fphm", this.jmData.getFp_hm());
/*  97:    */       }
/*  98:106 */       if (WlrzConst.isDebug()) {
/*  99:107 */         System.out.println("比较购方税号" + this.inData.getGf_nsrsbh() + "  " + 
/* 100:108 */           this.jmData.getGf_nsrsbh());
/* 101:    */       }
/* 102:109 */       if (!this.inData.getGf_nsrsbh().equals(this.jmData.getGf_nsrsbh()))
/* 103:    */       {
/* 104:110 */         this.wxyy |= 0x8;
/* 105:111 */         map.put("gf_nsrsbh", this.jmData.getGf_nsrsbh());
/* 106:    */       }
/* 107:115 */       double com_je = Math.abs(this.inData.getFp_je() - 
/* 108:116 */         this.jmData.getFp_je());
/* 109:117 */       if (com_je >= 1.0D)
/* 110:    */       {
/* 111:118 */         this.wxyy |= 0x4;
/* 112:119 */         map.put("je", new Double(this.jmData.getFp_je()).toString());
/* 113:    */       }
/* 114:121 */       if (WlrzConst.isDebug()) {
/* 115:122 */         System.out.println("比较发票金额" + this.inData.getFp_je() + "  " + 
/* 116:123 */           this.jmData.getFp_je());
/* 117:    */       }
/* 118:126 */       double com_se = Math.abs(this.inData.getFp_se() - 
/* 119:127 */         this.jmData.getFp_se());
/* 120:128 */       if (WlrzConst.isDebug()) {
/* 121:129 */         System.out.println("比较发票税额" + this.inData.getFp_se() + "  " + 
/* 122:130 */           this.jmData.getFp_se());
/* 123:    */       }
/* 124:131 */       if (com_se >= 1.0D)
/* 125:    */       {
/* 126:132 */         this.wxyy |= 0x2;
/* 127:133 */         map.put("se", new Double(this.jmData.getFp_se()).toString());
/* 128:    */       }
/* 129:137 */       if (WlrzConst.isDebug()) {
/* 130:138 */         System.out.println("比较销方税号" + this.inData.getXf_nsrsbh() + "  " + 
/* 131:139 */           this.jmData.getXf_nsrsbh());
/* 132:    */       }
/* 133:140 */       if (!this.inData.getXf_nsrsbh().equals(this.jmData.getXf_nsrsbh()))
/* 134:    */       {
/* 135:141 */         this.wxyy |= 0x1;
/* 136:142 */         map.put("xf_nsrsbh", this.inData.getXf_nsrsbh());
/* 137:    */       }
/* 138:145 */       if (this.inData.getQd_bz().trim().equals("Y"))
/* 139:    */       {
/* 140:146 */         if ((this.inData.getHzInfoList().size() == 0) || 
/* 141:147 */           (this.jmData.getHzInfoList().size() == 0) || 
/* 142:148 */           (this.inData.getHzInfoList().size() != this.jmData
/* 143:149 */           .getHzInfoList().size()))
/* 144:    */         {
/* 145:150 */           System.out.println("传入汉字数据与密文中汉字信息数量不符");
/* 146:151 */           this.wxyy |= 0x100;
/* 147:    */         }
/* 148:154 */         if (WlrzConst.isDebug()) {
/* 149:155 */           System.out.println("比较购方名称" + 
/* 150:156 */             this.inData.getHzInfoList().get(0) + 
/* 151:157 */             "  " + 
/* 152:158 */             replaceInvlidCharacter(
/* 153:159 */             (String)this.jmData.getHzInfoList().get(0)));
/* 154:    */         }
/* 155:161 */         if (!this.inData.getHzInfoList().get(0).equals(
/* 156:162 */           replaceInvlidCharacter(
/* 157:163 */           (String)this.jmData.getHzInfoList().get(0))))
/* 158:    */         {
/* 159:164 */           this.wxyy |= 0x200;
/* 160:165 */           map.put("gfmc", this.jmData.getHzInfoList().get(0));
/* 161:    */         }
/* 162:169 */         if (WlrzConst.isDebug()) {
/* 163:170 */           System.out.println("比较销方名称" + 
/* 164:171 */             this.inData.getHzInfoList().get(1) + 
/* 165:172 */             "  " + 
/* 166:173 */             replaceInvlidCharacter(
/* 167:174 */             (String)this.jmData.getHzInfoList().get(1)));
/* 168:    */         }
/* 169:175 */         if (!this.inData.getHzInfoList().get(1).equals(
/* 170:176 */           replaceInvlidCharacter(
/* 171:177 */           (String)this.jmData.getHzInfoList().get(1))))
/* 172:    */         {
/* 173:178 */           this.wxyy |= 0x400;
/* 174:179 */           map.put("xfmc", this.jmData.getHzInfoList().get(1));
/* 175:    */         }
/* 176:183 */         StringBuffer buf = new StringBuffer();
/* 177:185 */         for (int i = 3; i < this.inData.getHzInfoList().size(); i++)
/* 178:    */         {
/* 179:186 */           String inStr = ((String)this.inData.getHzInfoList().get(i))
/* 180:187 */             .trim();
/* 181:188 */           String jmStr = replaceInvlidCharacter(
/* 182:189 */             (String)this.jmData.getHzInfoList().get(i));
/* 183:190 */           if (i % 3 == 2)
/* 184:    */           {
/* 185:191 */             if (WlrzConst.isDebug()) {
/* 186:192 */               System.out.println("物品数量比较比对(行" + i / 3 + ")：" + 
/* 187:193 */                 inStr + "  " + jmStr);
/* 188:    */             }
/* 189:194 */             if ((!jmStr.equals("")) || (!inStr.equals("")))
/* 190:    */             {
/* 191:    */               try
/* 192:    */               {
/* 193:198 */                 jmStr = Format_DynamicWidth(jmStr, 9, 0);
/* 194:199 */                 jmStr = jmStr.replaceAll(",", "");
/* 195:    */                 
/* 196:201 */                 double inSL = Double.parseDouble(inStr);
/* 197:202 */                 double jmSL = Double.parseDouble(jmStr);
/* 198:203 */                 if (Math.abs(inSL - jmSL) <= 0.01D) {
/* 199:    */                   continue;
/* 200:    */                 }
/* 201:204 */                 this.wxyy |= 0x800;
/* 202:205 */                 if (this.isNewClient) {
/* 203:    */                   continue;
/* 204:    */                 }
/* 205:    */               }
/* 206:    */               catch (NumberFormatException e)
/* 207:    */               {
/* 208:210 */                 this.wxyy |= 0x800;
/* 209:211 */                 if (this.isNewClient) {
/* 210:    */                   continue;
/* 211:    */                 }
/* 212:    */               }
/* 213:212 */               break;
/* 214:    */             }
/* 215:    */           }
/* 216:    */           else
/* 217:    */           {
/* 218:216 */             if (WlrzConst.isDebug()) {
/* 219:217 */               System.out.println("物品名称与单位比对(行" + i / 3 + ")" + 
/* 220:218 */                 inStr + "  " + jmStr);
/* 221:    */             }
/* 222:219 */             if (!this.inData.getHzInfoList().get(i).equals(
/* 223:220 */               replaceInvlidCharacter(
/* 224:221 */               (String)this.jmData.getHzInfoList().get(i))))
/* 225:    */             {
/* 226:222 */               this.wxyy |= 0x800;
/* 227:223 */               if (!this.isNewClient) {
/* 228:    */                 break;
/* 229:    */               }
/* 230:224 */               buf.append(String.valueOf(i / 3) + 
/* 231:225 */                 String.valueOf(i % 3 + 1) + 
/* 232:226 */                 String.valueOf(this.jmData.getHzInfoList()
/* 233:227 */                 .get(i)) + "¤");
/* 234:    */             }
/* 235:    */           }
/* 236:    */         }
/* 237:235 */         String mx = buf.toString();
/* 238:236 */         if (WlrzConst.isDebug()) {
/* 239:237 */           System.out.println("MX== " + mx);
/* 240:    */         }
/* 241:239 */         if (mx.length() > 0) {
/* 242:240 */           map.put("mx", mx);
/* 243:    */         }
/* 244:    */       }
/* 245:246 */       this.rzjg = (this.wxyy == 0 ? 0 : 1);
/* 246:    */       
/* 247:    */ 
/* 248:249 */       System.out.println("[INFO] 比对结束，判断认证发票的状态 " + this.rzjg);
/* 249:250 */       if (this.rzjg == 0)
/* 250:    */       {
/* 251:252 */         if (cmpRdDate(this.rdDate, this.inData.getKprq()))
/* 252:    */         {
/* 253:253 */           this.fp_status = 1;
/* 254:254 */           this.wxyy = -1;
/* 255:255 */           this.rzjg = -5;
/* 256:256 */           return map;
/* 257:    */         }
/* 258:259 */         if (this.wxyy == 0) {
/* 259:261 */           if (!RzCheckKprqLimit.fpCheckKprqLimit(this.inData.getKprq(), 
/* 260:262 */             null))
/* 261:    */           {
/* 262:263 */             this.fp_status = 3;
/* 263:264 */             System.out.println("[INFO] fp_status = 3; " + 
/* 264:265 */               this.inData.getKprq());
/* 265:266 */             this.wxyy = -1;
/* 266:267 */             this.rzjg = -7;
/* 267:268 */             return map;
/* 268:    */           }
/* 269:    */         }
/* 270:    */       }
/* 271:    */     }
/* 272:    */     else
/* 273:    */     {
/* 274:274 */       this.fp_status = 0;
/* 275:275 */       this.wxyy = -1;
/* 276:276 */       this.rzjg = 1;
/* 277:277 */       return map;
/* 278:    */     }
/* 279:279 */     return map;
/* 280:    */   }
/* 281:    */   
/* 282:    */   String Format_DynamicWidth(String strValue, int DigitalWidth, int Decimal)
/* 283:    */   {
/* 284:288 */     int MaxDigit1 = 18;
/* 285:    */     
/* 286:290 */     String TrimValue = strValue;
/* 287:291 */     double FValue = Double.parseDouble(strValue);
/* 288:    */     
/* 289:293 */     DecimalFormat df1 = new DecimalFormat("");
/* 290:294 */     TrimValue = Double.toString(FValue);
/* 291:    */     
/* 292:296 */     DecimalFormat df2 = new DecimalFormat("#.0");
/* 293:297 */     DecimalFormat df3 = new DecimalFormat("#.");
/* 294:298 */     DecimalFormat df4 = new DecimalFormat("#0.");
/* 295:299 */     DecimalFormat df5 = new DecimalFormat("#0");
/* 296:300 */     DecimalFormat df6 = new DecimalFormat();
/* 297:301 */     DecimalFormat df = new DecimalFormat("#,##,###,####");
/* 298:303 */     if ((Math.abs(FValue) > 1.0D) && (
/* 299:304 */       (TrimValue.indexOf("e") > 0) || (TrimValue.indexOf("E") > 0)))
/* 300:    */     {
/* 301:306 */       if (Math.abs(FValue) < Math.pow(10.0D, MaxDigit1)) {
/* 302:308 */         df6.setMinimumFractionDigits(0);
/* 303:    */       }
/* 304:309 */       df6.setMaximumFractionDigits(0);
/* 305:310 */       TrimValue = df6.format(Double.parseDouble(TrimValue));
/* 306:311 */       return TrimValue;
/* 307:    */     }
/* 308:312 */     if ((Math.abs(FValue) < 1.0D) && (
/* 309:313 */       (TrimValue.indexOf("e") > 0) || (TrimValue.indexOf("E") > 0)))
/* 310:    */     {
/* 311:315 */       if (DigitalWidth == 0)
/* 312:    */       {
/* 313:316 */         if (Math.abs(FValue) > Math.pow(10.0D, -MaxDigit1))
/* 314:    */         {
/* 315:317 */           df6.setMinimumFractionDigits(MaxDigit1);
/* 316:318 */           df6.setMaximumFractionDigits(MaxDigit1);
/* 317:319 */           TrimValue = df6.format(Double.parseDouble(TrimValue));
/* 318:320 */           TrimZero(TrimValue, Decimal);
/* 319:    */         }
/* 320:    */       }
/* 321:322 */       else if ((DigitalWidth == 1) || (DigitalWidth == 2))
/* 322:    */       {
/* 323:323 */         TrimValue = "0";
/* 324:    */       }
/* 325:324 */       else if (DigitalWidth == 3)
/* 326:    */       {
/* 327:325 */         TrimValue = "0.0";
/* 328:    */       }
/* 329:326 */       else if (DigitalWidth > 3)
/* 330:    */       {
/* 331:327 */         df6.setMinimumFractionDigits(Math.min(MaxDigit1, DigitalWidth - (
/* 332:328 */           FValue < 0.0D ? 3 : 2)));
/* 333:329 */         df6.setMaximumFractionDigits(Math.min(MaxDigit1, DigitalWidth - (
/* 334:330 */           FValue < 0.0D ? 3 : 2)));
/* 335:331 */         TrimValue = df6.format(Double.parseDouble(TrimValue));
/* 336:332 */         TrimZero(TrimValue, Decimal);
/* 337:    */       }
/* 338:334 */       return TrimValue;
/* 339:    */     }
/* 340:337 */     if ((DigitalWidth == 0) && (Decimal > 0) && (GetDecimal(TrimValue) < Decimal))
/* 341:    */     {
/* 342:338 */       TrimValue = df2.format(FValue);
/* 343:    */     }
/* 344:339 */     else if (DigitalWidth == 1)
/* 345:    */     {
/* 346:340 */       TrimValue = df3.format(FValue);
/* 347:    */     }
/* 348:341 */     else if (DigitalWidth == 2)
/* 349:    */     {
/* 350:342 */       TrimValue = df4.format(FValue);
/* 351:    */     }
/* 352:343 */     else if (DigitalWidth >= 3)
/* 353:    */     {
/* 354:345 */       int IntNumber = Integer.toString((int)FValue).length();
/* 355:347 */       if (IntNumber >= DigitalWidth - 1)
/* 356:    */       {
/* 357:348 */         TrimValue = df5.format(FValue);
/* 358:    */       }
/* 359:351 */       else if (Decimal > 0)
/* 360:    */       {
/* 361:352 */         TrimZero(TrimValue, Decimal);
/* 362:    */       }
/* 363:353 */       else if ((Decimal == 0) && 
/* 364:354 */         (TrimValue.length() > DigitalWidth))
/* 365:    */       {
/* 366:355 */         df6.setMinimumFractionDigits(Math.min(MaxDigit1, 
/* 367:356 */           DigitalWidth - 1 - IntNumber));
/* 368:357 */         df6.setMaximumFractionDigits(Math.min(MaxDigit1, 
/* 369:358 */           DigitalWidth - 1 - IntNumber));
/* 370:359 */         TrimValue = df6.format(Double.parseDouble(TrimValue));
/* 371:    */         
/* 372:361 */         TrimZero(TrimValue, Decimal);
/* 373:    */       }
/* 374:    */     }
/* 375:367 */     if (TrimValue == null) {
/* 376:368 */       TrimValue = "0";
/* 377:    */     }
/* 378:370 */     return TrimValue;
/* 379:    */   }
/* 380:    */   
/* 381:    */   int GetDecimal(String Value)
/* 382:    */   {
/* 383:375 */     int Index = Value.indexOf(".");
/* 384:376 */     return Index > 0 ? Value.length() - Index : 0;
/* 385:    */   }
/* 386:    */   
/* 387:    */   void TrimZero(String Value, int Decimal)
/* 388:    */   {
/* 389:381 */     int MinDecimal = Decimal == 0 ? 0 : Decimal + 1;
/* 390:382 */     Value = Value.replaceAll(",", "");
/* 391:383 */     int Index = Value.indexOf(".");
/* 392:384 */     if (Index > 0) {
/* 393:385 */       for (int i = Value.length(); i >= Index + MinDecimal; i--)
/* 394:    */       {
/* 395:386 */         if (i == Index)
/* 396:    */         {
/* 397:387 */           String left = Value.substring(0, i);
/* 398:388 */           String right = Value.substring(i + 1, Value.length());
/* 399:389 */           Value = left + right;
/* 400:    */           
/* 401:391 */           break;
/* 402:    */         }
/* 403:392 */         if (Value.charAt(i - 1) != '0') {
/* 404:    */           break;
/* 405:    */         }
/* 406:393 */         String left1 = Value.substring(0, i - 1);
/* 407:394 */         String right1 = Value.substring(i, Value.length());
/* 408:395 */         Value = left1 + right1;
/* 409:    */       }
/* 410:    */     }
/* 411:    */   }
/* 412:    */   
/* 413:    */   public boolean isNewClient()
/* 414:    */   {
/* 415:403 */     return this.isNewClient;
/* 416:    */   }
/* 417:    */   
/* 418:    */   public void setNewClient(boolean isNewClient)
/* 419:    */   {
/* 420:407 */     this.isNewClient = isNewClient;
/* 421:    */   }
/* 422:    */   
/* 423:    */   private String replaceInvlidCharacter(String original)
/* 424:    */   {
/* 425:416 */     String newString = original.replaceAll("\t", "");
/* 426:417 */     newString = newString.replaceAll("\t", "");
/* 427:418 */     newString = newString.replaceAll(" ", "");
/* 428:419 */     newString = newString.replaceAll("　", "");
/* 429:    */     
/* 430:421 */     return newString;
/* 431:    */   }
/* 432:    */   
/* 433:    */   public int getFp_status()
/* 434:    */   {
/* 435:426 */     return this.fp_status;
/* 436:    */   }
/* 437:    */   
/* 438:    */   public InFpDataBean getInData()
/* 439:    */   {
/* 440:430 */     return this.inData;
/* 441:    */   }
/* 442:    */   
/* 443:    */   public JmFpDataBean getJmData()
/* 444:    */   {
/* 445:434 */     return this.jmData;
/* 446:    */   }
/* 447:    */   
/* 448:    */   Date getRdDate()
/* 449:    */   {
/* 450:438 */     return this.rdDate;
/* 451:    */   }
/* 452:    */   
/* 453:    */   public int getRzjg()
/* 454:    */   {
/* 455:442 */     return this.rzjg;
/* 456:    */   }
/* 457:    */   
/* 458:    */   public int getWxyy()
/* 459:    */   {
/* 460:446 */     return this.wxyy;
/* 461:    */   }
/* 462:    */   
/* 463:    */   public void setFp_status(int newFp_status)
/* 464:    */   {
/* 465:450 */     this.fp_status = newFp_status;
/* 466:    */   }
/* 467:    */   
/* 468:    */   public void setInData(InFpDataBean newInData)
/* 469:    */   {
/* 470:454 */     this.inData = newInData;
/* 471:    */   }
/* 472:    */   
/* 473:    */   public void setJmData(JmFpDataBean param1)
/* 474:    */   {
/* 475:458 */     this.jmData = param1;
/* 476:    */   }
/* 477:    */   
/* 478:    */   public void setRdDate(Date newRdDate)
/* 479:    */   {
/* 480:462 */     this.rdDate = newRdDate;
/* 481:    */   }
/* 482:    */ }


/* Location:           D:\htjs\document\wsrz\WsrzEjbInf\
 * Qualified Name:     gov.sat.tax.fwsk.wlrz.CmpHandler
 * JD-Core Version:    0.7.0.1
 */